class SoundPlayer:
    'Handels sound playing.'
    def __init__(self,mixer,on=1):
        self.mixer = mixer
        self.on = on
        self.frame_sounds = {}
        
    def update(self,dt):
        self.frame_sounds.clear()
        
    def play(self,sound,loops=0,force=0):
        if sound:
            # make sure we only play the same sound once every frame
            if self.frame_sounds.setdefault(sound,0) < 1:
                self.frame_sounds[sound] += 1
                ch = self.mixer.find_channel(force)
                if ch:
                    ch.play(sound,loops)
                    return ch
        return None

